package wj.tree;

import wj.WJValue;

public class IfBlockNode implements WJNode{

	private WJNode booleanExpression;
	private WJNode block;
	
	public IfBlockNode(WJNode booleanExpression, WJNode block){
		this.booleanExpression = booleanExpression;
		this.block = block;
	}
	
	public boolean isExpressionTrue(){
		WJValue boolVal = booleanExpression.evaluate();
		/*
		if(!boolVal.isBoolean())
			throw new RuntimeException("Expression in if statement is not a boolean expression.");
		*/
		return boolVal.toBoolean();
	}

	@Override
	public WJValue evaluate() {
		return block.evaluate();
	}
	
}
